<?php
/**
 * Created by PhpStorm.
 * User: Happy
 * Date: 2016/6/30 0030
 * Time: 15:54
 */
class export_excelPlugin  extends Plugin
{
    public  function  __construct($path='')
    {
        parent::__construct($path);
        $path=$this->c('plugin_path');
        $lib_path=$path.'/lib/excel.php';
        include($lib_path);
    }
    //导出execel第一个参数是数据数组格式，第二个参数是名字，默认是export，第三个参数是直接输出还是保存文件的参数
   public  function  export($data=array(),$name='export',$save_file=false){

       $excel=new Excel();
//$data=array_merge(array(array('姓名','年龄')),$data);
       $excel->addArray($data);
       $excel->addWorksheet($name);

       $excel->export($name,$save_file);
   }
   public function  download_file_demo(){
       $excel=new Excel();
       $data=array(
           array('姓名'=>'小明','age'=>23),
           array('姓名'=>'小张','age'=>24)
       );

//$data=array_merge(array(array('姓名','年龄')),$data);
       $excel->addArray($data);
       $excel->addWorksheet('name1');

       $excel->export('a.xls',false);
    }
   public  function  save_file_demo(){

       $excel=new Excel();
       $data=array(
           array('姓名'=>'小明','age'=>23),
           array('姓名'=>'小张','age'=>24)
       );

//$data=array_merge(array(array('姓名','年龄')),$data);
       $excel->addArray($data);
       $excel->addWorksheet('name1');

       $excel->export('a.xls',true);
   }
}